class TrendMap {
  
  PImage mapImage;
  Table locationTable;
  private int rowCount;
  String twitterStreamPath = "";
  Runnable runnable;
  Thread thread;

  private int MAXDIAMETER = 50;
  private float DECAYRATE = .95;
  private int LAX = 76;
  private int LAY = 235;
  private int CHIX = 412;
  private int CHIY = 143;
  private int NYX = 563;
  private int NYY = 128;
  PFont pfont;
  
  private int liveCount[] = new int[50];
  private int maxCount = 100;
  private int chiCount;
  private int laCount;
  private int nyCount;
  
  
  private int windowX;
  private int windowY;   //coordinates for defining window
  private int windowW;  
  private int windowH;
  
  public TrendMap (ThreeLittleBirds project4) {
    if (streamChoice == 2){
      DECAYRATE = 1.00;
      maxCount = 5;
      for (int i = 0; i<50; i++){
        liveCount[i] = 0;
      }
    }
    pfont = createFont("Times",12,true); 
    windowX = 200;  //no args constructor makes it full size
    windowY = 200;
    windowW = 640;
    windowH = 500;
    chiCount = 0;
    nyCount = 0;
    laCount = 0;
    //size (windowW, windowH);
    mapImage = loadImage("map.png");
    locationTable = new Table("locations.tsv");
    rowCount = locationTable.getRowCount();
    thread = new DataReader(project4, "local_tweets.txt");
    thread.start();
  }

  public void init(int wX, int wY, int wW, int wH){
   windowX = wX;   //initiate it with useful settings
   windowY = wY;
   windowH = wH;
   windowW = wW;
  }
  
  public void countDecay(){
   chiCount = (int)(chiCount * DECAYRATE);
   nyCount = (int)(nyCount *DECAYRATE);
   laCount = (int)(laCount*DECAYRATE);
  }
  

 public void update(){
   chiCount = chiCount + getChicagoCount();
   nyCount = nyCount + getNewYorkCount();
   laCount = laCount + getLosAngelesCount();
 }
 
 public void liveUpdate(){
   boolean outdated = true;
    for (int i = 0; i<50; i++){
      liveCount[i] = liveCount[i]+stateCounts[i];
      stateCounts[i]=0;
      liveCount[i] = (int)(liveCount[i]*DECAYRATE); 
    }
    //Date d = new Date();
  // do { if(livePastTenMin.get().double < (((double)d.getMinutes)-10) || livePastTenMin.get().double <
      
   // }while(outdated);
 } 
   
 public int getChicagoCount(){
    int currentCount = chicagoCount;
    chicagoCount =0;
    return currentCount;    
  }  
  
  public int getNewYorkCount(){
    int currentCount = newYorkCount;
    newYorkCount =0;
    return currentCount;  
  }  
  
  public int getLosAngelesCount(){
    int currentCount = losAngelesCount;
    losAngelesCount =0;
    return currentCount;  
  }  
  
  

  public void drawTrendMap(){
       background(255);
        int plotX1 = 170;
        int  plotX2 = width - 25;
        int plotY1 = 30; 
        int plotY2 = height - 25;
       image(mapImage, plotX1, plotY1, plotX2-plotX1, plotY2-plotY1);
      switch (streamChoice){
        case 1:{update();
                drawCircle(CHIX, CHIY, chiCount);
                drawCircle(LAX, LAY, laCount);
                drawCircle(NYX, NYY, nyCount);
                countDecay();
                break;}
        case 2:{liveUpdate();
                for (int i = 0; i<50; i++){
                  drawCircle(locationTable.getInt(i, 1), locationTable.getInt(i, 2), liveCount[i]);
                }
                 break;}
        default: {}
    }
       fill(255, 0, 0, 255);
       textAlign(CENTER);
       textFont(pfont);
       text(currentDateTime, windowW/2, windowH/20);
      }


  public void drawCircle(int xCoord, int yCoord, int sizeCount){
    float diameter = 0;
    if (sizeCount>maxCount) maxCount=sizeCount;
    diameter = ((float)sizeCount/(float)maxCount)*MAXDIAMETER;
    fill(#EC5166, 150);
    ellipse (xCoord, yCoord, diameter, diameter); 
  }

/*
  public void findClosest(){
  //find which state is gonna be added to
  }*/
  
}
